<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>选择会员卡</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/app/admin/component/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/app/admin/component/pear/css/pear.css" media="all">
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-form" lay-filter="card-search">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">卡号</label>
                        <div class="layui-input-inline">
                            <input type="text" name="card_no" placeholder="请输入卡号" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-card-search">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                    </div>
                </div>
            </div>
            
            <table id="LAY-card-list" lay-filter="LAY-card-list"></table>
        </div>
    </div>
</div>

<script src="/app/admin/component/layui/layui.js"></script>
<script src="/app/admin/component/pear/pear.js"></script>
<script>
layui.use(['table', 'form', 'layer'], function(){
    var $ = layui.$
        ,table = layui.table
        ,form = layui.form
        ,layer = layui.layer;
    
    // 渲染表格
    table.render({
        elem: '#LAY-card-list'
        ,url: '/app/ky_shouyin/member/getUnusedCards'
        ,cols: [[
            {type: 'radio', fixed: 'left'}
            ,{field: 'card_no', title: '卡号', width: 150}
            ,{field: 'created_at', title: '生成时间', width: 180}
        ]]
        ,page: true
        ,limit: 10
        ,height: 'full-130'
        ,text: {
            none: '暂无可用会员卡'
        }
    });
    
    // 搜索
    form.on('submit(LAY-card-search)', function(data){
        var field = data.field;
        
        table.reload('LAY-card-list', {
            where: field
        });
        
        return false;
    });
    
    // 监听选择
    table.on('radio(LAY-card-list)', function(obj){
        window.selectedCard = obj.data;
    });
});

// 提交选中的卡号
window.submitSelectedCard = function(){
    if (!window.selectedCard) {
        layer.msg('请选择会员卡', {icon: 2});
        return;
    }
    
    var index = parent.layer.getFrameIndex(window.name);
    parent.layui.jquery('#card_no').val(window.selectedCard.card_no);
    parent.layer.close(index);
};
</script>

<div class="layui-form-item layui-hide">
    <input type="button" lay-submit lay-filter="LAY-app-submit" id="LAY-app-submit" value="确认">
</div>
</body>
</html> 